package com.modouyu.demo211.demo211;

import com.modouyu.demo211.demo211.controller.HelloController;
import com.modouyu.demo211.demo211.service.FooProperties;
import com.modouyu.demo211.demo211.service.PostInfo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.context.ApplicationContext;

import java.util.List;

@SpringBootApplication
public class Demo211Application {

    public static void main(String[] args) {

        //上下文容器
        ApplicationContext context = SpringApplication.run(Demo211Application.class, args);

        Binder binder = Binder.get(context.getEnvironment());
        HelloController helloController = context.getBean(HelloController.class);
        System.out.println(helloController);



        //绑定简单配置
        FooProperties fooProperties = binder.bind("com.modouyu", Bindable.of(FooProperties.class)).get();
        System.out.println(fooProperties.getFoo());

        // 绑定List配置
        List<String> post = binder.bind("com.modouyu.post", Bindable.listOf(String.class)).get();
        System.out.println(post);

        List<PostInfo> posts = binder.bind("com.modouyu.posts", Bindable.listOf(PostInfo.class)).get();
        System.out.println(posts);

        // 读取配置
        System.out.println(context.getEnvironment().containsProperty("com.modouyu.database-platform"));
        System.out.println(context.getEnvironment().containsProperty("com.modouyu.databasePlatform"));


    }
}
